package com.ss.android.article.base.feature.update.b;

import android.content.Context;
import android.os.Handler;

import com.bytedance.article.common.c.TTUtils;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.UrlBuilder;

import org.json.JSONObject;

public final class b extends AbsApiThread {
    private com.ss.android.article.base.feature.update.a.b a;
    private Handler b;
    private Context c;
    private int d;

    public b(Context arg2, Handler arg3, com.ss.android.article.base.feature.update.a.b arg4) {

        this.d = 3;
        Context v0 = arg2 != null ? arg2.getApplicationContext() : null;
        this.c = v0;
        this.b = arg3;
        this.a = arg4;
    }

    public b(Context arg2, com.ss.android.article.base.feature.update.a.b arg3) {
        this(arg2, null, arg3);
    }

    private static boolean a(Context arg10, int arg11, com.ss.android.article.base.feature.update.a.b arg12) {
        long v8 = 0;
        boolean v0 = false;
        int v3 = 0;
        while (v3 < arg11) {
            try {
                UrlBuilder v4 = new UrlBuilder();
                String v2_1;
                switch (arg12.a) {
                    case 0: {
                        if (arg12.b <= v8) {
                            return v0;
                        }

                        v2_1 = ArticleConstants.dongtaiDiggActionUrl;
                        v4.addParam("id", arg12.b);
                        break;
                    }
                    case 1: {
                        if (arg12.b <= v8) {
                            return v0;
                        }
                        v2_1 = ArticleConstants.dongtaiCommentActionUrl;
                        v4.addParam("id", arg12.b);
                        v4.addParam("content", arg12.c);
                        v4.addParam("reply_comment_id", arg12.d);
                        v4.addParam("reply_user_id", arg12.e);
                        break;
                    }
                    case 4: {
                        if (arg12.j <= v8) {
                            return v0;
                        }

                        v2_1 = ArticleConstants.dongtaiCommentDiggUrl;
                        v4.addParam("comment_id", arg12.j);
                        break;
                    }
                    default:
                        return v0;
                }

                v2_1 = NetworkUtils.executePost(20480, v2_1, v4.mList);
                if (v2_1 == null) {
                    return v0;
                }

                JSONObject v4_1 = new JSONObject(v2_1);
                if (!v4_1.optString("message").equals("success")) {
                    return v0;
                }

                JSONObject v2_2 = v4_1.optJSONObject("data");
                if (v2_2 == null) {
                    return v0;
                }

                switch (arg12.a) {
                    case 1: {
                        v4_1 = v2_2.optJSONObject("comment");
                        if (v4_1 != null) {
                            arg12.g = com.ss.android.article.base.feature.update.a.c.a(v4_1);
                            v2_2 = v2_2.optJSONObject("forward_item");
                            if (v2_2 != null) {
                                com.ss.android.article.base.feature.update.a.d.b(v2_2);
                            }
                        } else {
                            return v0;
                        }

                        break;
                    }
                }
                v0 = true;
            } catch (Throwable v2) {
                int v2_3 = TTUtils.getErrorCode(arg10, v2);
                boolean v2_4;
                if (v2_3 == 13 || v2_3 == 14) {
                    v2_4 = true;
                } else {
                    v2_4 = v0;
                }

                if (!v2_4) {
                    return v0;
                }
                ++v3;
                continue;
            }
        }
        return v0;
    }

    public final void run() {
        int v0 = a(this.c, this.d, this.a) ? 1005 : 1006;
        if (this.b != null) {
            this.b.sendMessage(this.b.obtainMessage(v0, this.a));
        }
    }
}

